﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SOverify.aspx.cs" Inherits="sWarranty.WEB.SOverify" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="../UC/Header.ascx" TagName="Header" TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../CSS/table.css" />
    <link rel="stylesheet" type="text/css" href="../CSS/Menu.css" />
    <link href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" rel="stylesheet"
        type="text/css" />
    <script src="../JS/jquery-1.8.2.js" type="text/javascript"></script>
    <script src="../JS/jquery-ui.js" type="text/javascript"></script>
    <script src="../JS/Menu.js" type="text/javascript"></script>
    <link href="../JS/chosen-master/chosen/chosen.css" rel="stylesheet" type="text/css" />
    <script src="../JS/chosen-master/chosen/chosen.jquery.js" type="text/javascript"></script>
    <script src="../JS/jquery.stickytableheaders.js" type="text/javascript"></script>
    <script src="../JS/jquery.simplemodal.js" type="text/javascript"></script>
    <link href="../JS/basic/css/basic_ie.css" rel="stylesheet" type="text/css" />
    <link href="../JS/basic/css/basic.css" rel="stylesheet" type="text/css" />
    <link href="../JS/basic/css/demo.css" rel="stylesheet" type="text/css" />
    <script src="../JS/jquery.dataTables.js" type="text/javascript"></script>
    <script>
        $(document).ready(function () {
            $("#txtFromDate").datepicker({ dateFormat: 'yy/mm/dd' });
            $("#txtToDate").datepicker({ dateFormat: 'yy/mm/dd' });

            $("#txtFromDate").attr('readOnly', 'true');
            $("#txtToDate").attr('readOnly', 'true');

            //$("table").stickyTableHeaders();

            SetLogger();
        });
        function openPopUp(popUrl, type) {
            var name = 'popUp';
            var appearence = 'dependent=no,menubar=no,resizable=yes,scrollbars=1,' +
                  'status=yes,toolbar=yes,titlebar=yes,' +
                  'width=' + window.screen.availWidth * 80 / 100 + ', height=' + window.screen.availHeight * 80 / 100 + ',resizable:yes,center:yes';
            var openWindow = '';
            if (type == 'open')
                openWindow = window.open(popUrl, name, appearence);
            if (type == 'popup')
                openWindow = window.showModalDialog(popUrl, name, appearence);
            openWindow.focus();
        }
       
    </script>
    <style type="text/css">
        .rgMasterTable
        {
            font-size: 11px !important;
            font-family: tahoma !important;
        }
    </style>
    <script>
        $(document).ready(function () {
            $("#txtFromDate").attr('readOnly', 'true');
            $("#txtToDate").attr('readOnly', 'true');
            //$("table").stickyTableHeaders();
            //SetLogger();
        });

        function FormatTable() {
            $('.datatablecss').dataTable({
                "sScrollY": "200px",
                "bPaginate": false,
                "bFilter": true,
                "bScrollCollapse": true
            });
            //new FixedColumns(oTable);
        };
        function ShowPopupfindCustomer() {
            var b = $('#txtBillCode').val();
            var txtBillPopup = document.getElementById('txtBillPopup');
            txtBillPopup.value = b;

            $('#divFindBill').modal();
            if (b.length > 2) {
                findBill();
            }
        }
        function findBill() {
            var bill = $('#txtBillPopup').val();
            if (bill.length <= 2) {
                alert("You must input at least 3 character of BILL");
                return;
            }
            $('#imageLoadingPopup2').show();
            var options = {
                type: 'POST',
                url: 'WebService1.asmx/findBill',
                data: '{bill: "' + bill + '"}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (msg) {
                    $("#divBillPopup").html(msg.d);
                    $('#imageLoadingPopup2').hide();
                    FormatTable();
                },
                error: function (msg) {
                    $('#imageLoadingPopup2').hide();
                    alert("Unknow Error: " + msg.d)
                }
            };
            $.ajax(options);
        }
        function setSelectOnPopup2(rowTotal, curRow, bill) {
            var txtBillCode = document.getElementById('txtBillCode');
            txtBillCode.value = bill;

            $.modal.close();

        }
        function DoFindSO() {
            $('#imageLoading1').show();
            var p_shop_code = "";
            var p_shop_name = "";
            var p_f_dt = "";
            var p_t_dt = "";
            var p_vrf_flag = "%";
            var p_cfm_flag = "";
            var p_user_region = "";
            var p_region_id = "%";

            p_shop_code = document.getElementById('txtShopCode').value;
            p_shop_name = document.getElementById('txtShopName').value;
            p_f_dt = document.getElementById('txtFromDate').value;
            p_t_dt = document.getElementById('txtToDate').value;
            p_cfm_flag = $('#dropConfirm').val();
            p_user_region = document.getElementById('hiddenUserRegion').value;
            p_region_id = $('#dropRegion').val();

            var options = {
                type: 'POST',
                url: 'WebService1.asmx/fillSO',
                data: '{p_shop_code: "' + p_shop_code + '", p_shop_name: "' + p_shop_name + '",p_f_dt: "' + p_f_dt + '", p_t_dt: "' + p_t_dt + '",p_vrf_flag: "' + p_vrf_flag + '", p_cfm_flag: "' + p_cfm_flag + '",p_user_region: "' + p_user_region + '", p_region_id: "' + p_region_id + '"}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (msg) {
                    $("#divBill").html(msg.d);
                    $('#imageLoading1').hide();
                    FormatTable();
                },
                error: function (msg) {
                    $('#imageLoading1').hide();
                    alert("Unknow Error: " + msg.d)
                }
            };
            $.ajax(options);
        }

        function doConfirm(total, current, SHOP_CODE, SHOP_CELL, EDI_NO, SERIAL_NO, MODEL, SUFFIX,
        SELLOUT_DATE, SELLIN_DATE, user_cell) {

            var comment = $('#txtCmt' + EDI_NO).val();
            var curUser = $('#hiddenCurUser').val();
            var xxx = ("SHOP_CODE: " + SHOP_CODE + "\n"
                + "SHOP_CELL: " + SHOP_CELL + "\n"
                + "EDI_NO: " + EDI_NO + "\n"
                + "SERIAL_NO: " + SERIAL_NO + "\n"
                + "MODEL: " + MODEL + "\n"
                + "SUFFIX: " + SUFFIX + "\n"
                + "SELLOUT_DATE: " + SELLOUT_DATE + "\n"
                + "SELLIN_DATE: " + SELLIN_DATE + "\n"
                + "USER_CELL: " + user_cell + "\n"
                + "\n\n Are you sure confirm this data...?");

            if (confirm(xxx) == true) {
                var options = {
                    type: 'POST',
                    url: 'WebService1.asmx/doConfirmSO',
                    data: '{p_shop_code: "' + SHOP_CODE + '", p_shop_cell: "' + SHOP_CELL + '", p_edi_no: "' + EDI_NO + '", p_serial_no: "'
                    + SERIAL_NO + '", p_model: "' + MODEL + '", p_suffix: "' + SUFFIX + '", p_sellout_date: "' + SELLOUT_DATE + '", p_sellin_date: "'
                     + SELLIN_DATE + '", p_user_cell: "' + user_cell + '", p_cfm_comment: "' + comment + '", p_cfm_user: "' + curUser + '"}',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.d == "DONE") {//OK
                            $("#btnSelect" + current).hide();
                            $("#imgSelect" + current).show();
                            alert('DONE');
                        }
                        else {//have sql Error, 
                            //                            $("#span" + sn).text(msg.d);
                            //                            $("#span" + sn).css({ "color": "red", "opacity": ".50" });
                            //                            $('#btn' + sn).attr("disabled", false);
                            //                            $('#btn' + sn).attr("value", "Reject");
                            alert('FAIL');
                        }
                    },
                    error: function (msg) {
                        alert("Unknow Error: " + msg.d)
                    }
                };
                $.ajax(options);
            }
        }

        function ttt(s) {
            var msg = document.getElementById(s);
            $('#hid1').val(s + "|" + msg.value);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ksdjfl" runat="server">
    </asp:ScriptManager>
    <input type="hidden" runat="server" id="hiddenCurUser" clientidmode="Static" />
    <input type="hidden" runat="server" id="hiddenUserRegion" clientidmode="Static" />
    <uc1:Header ID="Header1" runat="server" />
    <div class="Mid">
        <div class="Mid1">
            <div id="DataContent">
                <%-- <div>
                    Nội dung bên trái
                </div>--%>
                <div>
                    <!-- DataGrid Start -->
                    <div class="Search">
                        <table>
                            <tr>
                                <td style="background-color: #F7F7F7">
                                    <asp:TextBox ID="txtBillCode" ClientIDMode="Static" Visible="false" runat="server"></asp:TextBox>
                                    <input type='button' class="button Float-right" onclick="ShowPopupfindCustomer()"
                                        style="width: 20px; display: none;" value="..." />
                                    Period:
                                </td>
                                <td>
                                    <asp:TextBox ID="txtFromDate" ClientIDMode="Static" runat="server" Width="80px" Enabled="true"></asp:TextBox>
                                    <asp:TextBox ID="txtToDate" ClientIDMode="Static" runat="server" Width="80px" Enabled="true"></asp:TextBox>
                                </td>
                                <td style='width: 10px'>
                                </td>
                                <td style="background-color: #F7F7F7">
                                    Shop code:
                                </td>
                                <td>
                                    <asp:TextBox ID="txtShopCode" ClientIDMode="Static" runat="server" Width="150px"></asp:TextBox>
                                </td>
                                <td style='width: 10px'>
                                </td>
                                <td style="background-color: #F7F7F7">
                                    Confirm:
                                </td>
                                <td>
                                    <asp:DropDownList ID="dropConfirm" runat="server" Width="100px" CssClass="chzn-select">
                                        <asp:ListItem Value="%" Text="All"></asp:ListItem>
                                        <asp:ListItem Value="N" Text="N"></asp:ListItem>
                                        <asp:ListItem Value="Y" Text="Y"></asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                                <td style='width: 10px'>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td style="background-color: #F7F7F7">
                                    Region:
                                </td>
                                <td>
                                    <asp:DropDownList ID="dropRegion" ClientIDMode="Static" Width="100%" runat="server"
                                        CssClass="chzn-select">
                                        <asp:ListItem Value="00" Text="Select"></asp:ListItem>
                                        <asp:ListItem Value="01" Text="NORTH"></asp:ListItem>
                                        <asp:ListItem Value="02" Text="MIDDLE"></asp:ListItem>
                                        <asp:ListItem Value="03" Text="SOUTH"></asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                                <td style='width: 10px'>
                                </td>
                                <td style="background-color: #F7F7F7">
                                    Shop Name :
                                </td>
                                <td>
                                    <asp:TextBox ID="txtShopName" ClientIDMode="Static" runat="server" Width="150px"></asp:TextBox>
                                </td>
                                <td style='width: 10px'>
                                </td>
                                <td style="background-color: #F7F7F7">
                                    Verified:
                                </td>
                                <td>
                                    <asp:DropDownList ID="dropVerified" ClientIDMode="Static" Width="100px" runat="server"
                                        CssClass="chzn-select">
                                        <asp:ListItem Value="%" Text="Select"></asp:ListItem>
                                        <asp:ListItem Value="N" Text="N"></asp:ListItem>
                                        <asp:ListItem Value="Y" Text="Y"></asp:ListItem>
                                        <asp:ListItem Value="1" Text="1"></asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                                <td style='width: 10px'>
                                </td>
                                <td>
                                    <asp:Button ID="btnExcel" runat="server" CssClass="button Float-right" Width="60px"
                                        Text="Export" OnClick="btnExcel_Click" />
                                    <asp:Button ID="btnSearch" runat="server" class="button Float-right" Width="60px"
                                        OnClick="Button1_Click" Text="Search" />
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div>
                        <div class="TitleCont">
                            Confirm data
                            <img id='imgLoadingxyz' src='../images/oader-grey.gif' style='display: none' />
                        </div>
                        <div style='padding-bottom: 10px; text-align: center; display: none' id="imageLoading1">
                            <img src="../IMAGES/red_loading.gif" />
                        </div>
                        <div id="divBill" style="height: 100%; overflow: auto; width: 100%;">
                        </div>
                    </div>
                </div>
            </div>
            <asp:HiddenField ID="hid1" Value="123" ClientIDMode="Static" runat="server" />
            <div id="xxx" style="height: 100%; overflow: auto;">
                <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" CellSpacing="0"
                    CssClass="RadGridCustomClass" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource"
                    OnColumnCreated="RadGrid1_ColumnCreated" OnItemCommand="RadGrid1_ItemCommand"
                    Skin="Office2007" OnItemDataBound="RadGrid1_ItemDataBound">
                    <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="true" ReorderColumnsOnClient="True">
                        <Selecting AllowRowSelect="false" />
                    </ClientSettings>
                    <MasterTableView>
                        <PagerStyle AlwaysVisible="True" />
                        <Columns>
                            <telerik:GridTemplateColumn HeaderText="Actions">
                                <ItemTemplate>
                                    <asp:Button ID="btnEdit" runat="server" ToolTip="Edit" CommandName="uiroi" Text="Confirm" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Msg">
                                <ItemTemplate>
                                    <input type="text" id="txt<%# Eval("EDI_NO")%>" onchange="ttt('txt<%# Eval("EDI_NO")%>')" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
            </div>
            <div class="Clear_both">
            </div>
            <div id="divFindBill" runat="server" style="display: block;">
                <table id="newspaper-b">
                    <tbody>
                        <tr>
                            <td>
                                Customer Name:
                            </td>
                            <td>
                                <input type="text" id="txtBillPopup" />
                            </td>
                            <td>
                                <input type='button' id="btnFindBillPopup" onclick="findBill()" value="Search" style="width: 80px;"
                                    class="button" />
                            </td>
                        </tr>
                    </tbody>
                </table>
                <div style='padding-bottom: 10px; text-align: center; display: none' id="imageLoadingPopup2">
                    <img src="../IMAGES/red_loading.gif" />
                </div>
                <div style='padding-bottom: 20px; text-align: center;'>
                </div>
                <div id="divBillPopup" style="width: 100%; overflow: auto;">
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">        $(".chzn-select").chosen(); </script>
    </form>
</body>
</html>
